import asyncio
import websockets

async def tcp_to_websocket():
    async with websockets.connect('ws://localhost:9002') as ws:
        reader, writer = await asyncio.open_connection('localhost', 1717)
        try:
            while True:
                data = await reader.read(4096)
                if not data:
                    break
                await ws.send(data)
        except KeyboardInterrupt as e:
            print("Exiting...")
        except Exception as e:
            print(f"Error: {e}")
        finally:
            writer.close()

if __name__ == "__main__":
    asyncio.run(tcp_to_websocket())